package com.smmisia.article.core;


import com.smmisia.article.entity.Score;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class ItemCF {


    public static List<Integer> recommend(Integer itemId, List<Score> list) {
        //按物品分组
        Map<Integer, List<Score>> itemMap = list.stream().collect(Collectors.groupingBy(Score::getArticleId));
        //获取其他物品与当前物品的关系值
        Map<Integer, Double> itemDisMap = CoreMath.computeNeighbor(itemId, itemMap, 1);
        //获取关系最近物品
        double maxValue = Collections.max(itemDisMap.values());
        return itemDisMap.entrySet().stream().filter(e -> e.getValue() == maxValue).map(Map.Entry::getKey).collect(Collectors.toList());
    }
}